/**
 * @author 蒙伟明
 * @data 2020年6月14日
 */
package com.ysxm.service.adminservice.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ysxm.dao.adminmapper.MoviesDao;
import com.ysxm.entity.Comment;
import com.ysxm.entity.Movies;
import com.ysxm.entity.Moviessorrt;
import com.ysxm.service.adminservice.MoviesService;
import com.ysxm.util.CustomException;

/**
 * @author mwm
 *
 */
@Service
@Transactional
public class MoviesServiceImpl implements MoviesService {
	@Autowired
	private MoviesDao moviesDao;

	@Override
	public boolean addMovise(Movies movies) {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String mtime = sdf.format(date.getTime());
		movies.setMoviesuploadtime(mtime);
		try {
			Boolean b = moviesDao.addMovise(movies);
			return b;
		} catch (Exception e) {
			e.printStackTrace();
			throw new CustomException("添加失败");
		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ysxm.service.adminservice.MoviesService#updateMovise(com.ysxm.entity.
	 * Movies)
	 */
	@Override
	public boolean updateMovise(Movies movies) {
		try {
			Boolean b = moviesDao.updateMovise(movies);
			return b;
		} catch (Exception e) {
			e.printStackTrace();
			throw new CustomException("修改失败");
		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.ysxm.service.adminservice.MoviesService#deleteMovise(java.lang.
	 * Integer)
	 */
	@Override
	public boolean deleteMovise(Integer[] mid) {
		try {
			Boolean b = moviesDao.deleteMovise(mid);
			return b;

		} catch (Exception e) {
			e.printStackTrace();
			throw new CustomException("删除失败,有人已收藏");
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ysxm.service.adminservice.MoviesService#findMoviseById(java.lang.
	 * Integer)
	 */
	@Override
	public Movies findMoviseById(Integer mid) {

		try {
			Movies movies = moviesDao.findMoviseById(mid);
			int count = moviesDao.collectcount(mid);
			movies.setCount(count);
			return movies;
		} catch (Exception e) {
			e.printStackTrace();
			throw new CustomException("查看失败");
		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.ysxm.service.adminservice.MoviesService#findAllMovise()
	 */
	@Override
	public List<Movies> findAllMovise(int pageNum, int pageSize) {
		try {
			List<Movies> mList = moviesDao.findAllMovise(pageSize, pageSize);
			return mList;
		} catch (Exception e) {
			e.printStackTrace();
			throw new CustomException("查看失败");
		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * 
	 */
	@Override
	public List<Movies> findMoviseListBy(Movies movies) {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 */
	@Override
	public List<Moviessorrt> findMoviessortByMsid(Integer msid) {
		try {
			List<Moviessorrt> msList = moviesDao.findMoviessortByMsid(msid);
			return msList;
		} catch (Exception e) {
			e.printStackTrace();
			throw new CustomException("查看失败");
		}

	}

	/*
	 */
	@Override
	public List<Movies> checkMovies(String moviesname,String moviesdescribe) {

		try {
			List<Movies> mlist = moviesDao.checkMovies(moviesname,moviesdescribe);
			return mlist;
		} catch (Exception e) {
			e.printStackTrace();
			throw new CustomException("查看失败");
		}

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.ysxm.service.adminservice.MoviesService#collectcount()
	 */
	@Override
	public int collectcount(Integer mid) {
		try {
			int count;
			count = moviesDao.collectcount(mid);
			return count;
		} catch (Exception e) {
			e.printStackTrace();
			throw new CustomException("显示失败");
		}

	}

	/* (non-Javadoc)
	 * @see com.ysxm.service.adminservice.MoviesService#findAllComment()
	 */
	@Override
	public List<Comment> findAllComment() {
		try {
			List<Comment> cmList = moviesDao.findAllComment();
			return cmList;
		} catch (Exception e) {
			e.printStackTrace();
			throw new CustomException("查看失败");
		}
	}

	/* (non-Javadoc)
	 * @see com.ysxm.service.adminservice.MoviesService#deleteComment(java.lang.Integer)
	 */
	@Override
	public boolean deleteComment(Integer[] cid) {
		try {
			boolean result = moviesDao.deleteComment(cid);
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			throw new CustomException("查看失败");
		}
	}

	/* (non-Javadoc)
	 * @see com.ysxm.service.adminservice.MoviesService#passComment(com.ysxm.entity.Comment)
	 */
	@Override
	public boolean passComment(Integer[] cid) {
		try {
			@SuppressWarnings("unused")
			Boolean result=moviesDao.passComment(cid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

}
